// 全局【过滤器】的方法

/**
 * Description:是否为空
 * Author:ybt
 * Date:2020/7/6
 */
const isNullOrEmpty = function(val) {
    if (val == null || val == "" || typeof(val) == undefined) {
        return true;
    } else {
        return false;
    }
};

/**
 * Description:时间格式化
 * Author:ybt
 * Date:2020/7/6
 */
const timeFormat = (value, format) => {
    // padStart 和 padEnd 是ES6提供的字符串填充方法
    let date = new Date(value);
    let y = date.getFullYear();
    let m = (date.getMonth() + 1).toString().padStart(2, '0');
    let d = date.getDate().toString().padStart(2, '0');
    let h = date.getHours().toString().padStart(2, '0');
    let min = date.getMinutes().toString().padStart(2, '0');
    let s = date.getSeconds().toString().padStart(2, '0');
    let result = "";
    if (format == undefined) {
        // result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
        //     h < 10 ? "0" + h : h
        //     }:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
        result = `${y}-${m}-${d} ${h}:${min}:${s}`
    } else {
        if (format.toLowerCase() == "yyyy-mm-dd") {
            // result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
            result = `${y}-${m}-${d}`
        }
        if (format.toLowerCase() == "yyyy-mm") {
            // result = `${y}-${m < 10 ? "0" + m : m}`;
            result = `${y}-${m}`
        }
        if (format.toLowerCase() == "mm-dd") {
            // result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
            result = `${m}-${d}`
        }
        if (format.toLowerCase() == "hh:mm") {
            // result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
            result = `${h}:${min}`
        }
        if (format.toLowerCase() == "yyyy") {
            result = `${y}`;
        }
    }
    return result;
};

export {
    isNullOrEmpty,
    timeFormat
}
